#!/bin/bash

OUTPUT="merged-statistics.txt"

echo "🔄 Merging all statistics-*.txt into $OUTPUT ..."
echo "" > "$OUTPUT"

for file in statistics-*.txt; do
    if [[ -f "$file" ]]; then

        # 提取策略名称与是否启用 combiner
        # 格式：statistics-<partitioner>-<combinerFlag>.txt
        name=$(echo "$file" | sed 's/^statistics-//' | sed 's/\.txt$//')
        partitioner=$(echo "$name" | awk -F'-' '{print $1}')
        combiner=$(echo "$name" | awk -F'-' '{print $2}')

        echo "==========================================" >> "$OUTPUT"
        echo "Partitioner       : $partitioner" >> "$OUTPUT"
        echo "Combiner Enabled? : $combiner" >> "$OUTPUT"
        echo "Source File       : $file" >> "$OUTPUT"
        echo "==========================================" >> "$OUTPUT"
        echo "" >> "$OUTPUT"

        # 写内容
        cat "$file" >> "$OUTPUT"
        echo "" >> "$OUTPUT"
        echo "" >> "$OUTPUT"
    fi
done

echo "✅ Merge complete: $OUTPUT"
